home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / bbs / pad321.zip / VERIFY.MH < prev    next >
Text File  |  1996-10-20  |  12KB  |  373 lines

  1. #ifndef __VERIFY_MH
  2. #define __VERIFY_MH
  3.  
  4. #ifndef __STRING_MH
  5. #include "string.mh"
  6. #endif
  7.  
  8. #ifndef __SETTINGS_MH
  9. #include "settings.mh"
  10. #endif
  11.  
  12. #ifndef __IN_MH
  13. #include "in.mh"
  14. #endif
  15.  
  16. #ifndef __FILE_MH
  17. #include "file.mh"
  18. #endif
  19.  
  20. #ifndef __HACKS_MH
  21. #include "hacks.mh"
  22. #endif
  23.  
  24. #ifndef __OUT_MH
  25. #include "out.mh"
  26. #endif
  27.  
  28. #ifndef __GENERAL_MH
  29. #include "general.mh"
  30. #endif
  31.  
  32. #include <rand.mh>
  33.  
  34. bool: hangupFlag;
  35.  
  36. void padlock_log (string: message) {
  37.   int: fd;
  38.   long: t;
  39.   struct _stamp: ts;
  40.  
  41.   if (log_file = "") return;
  42.   if (fileexists (log_file)) {
  43.     fd := open (log_file,IOPEN_APPEND | IOPEN_WRITE);
  44.     }
  45.   else fd := open (log_file, IOPEN_CREATE | IOPEN_WRITE);
  46.  
  47.   if (fd = -1) {
  48.     log (str_cant_open_log + log_file);
  49.     print (str_cant_open + log_file);
  50.     };
  51.  
  52.   t := time ();
  53.   long_to_stamp (t,ts);
  54.   writeln (fd,stamp_string (ts) + " " + usr.name + " " + message);
  55.   close (fd);
  56.   }
  57.  
  58. int checkCodeWord (string: codeWord, string: message) {
  59.   int: passwordAttempts;
  60.   string: codeWordAttempt;
  61.   codeWord := strupper (codeWord);
  62.   for (passwordAttempts = 0; passwordAttempts < 3; passwordAttempts := passwordAttempts + 1) {
  63.     print (message);
  64.     input_str_ani (codeWordAttempt);
  65.     codeWordAttempt := strupper (codeWordAttempt);
  66.     if (codeWord = codeWordAttempt) return True;
  67.     print (str_bad_password_attempt + itostr (passwordAttempts+1) 
  68.       + str_bad_password_attempt_sfx);
  69.     };
  70.   vidsync ();
  71.   return False;
  72.   }
  73.  
  74. int checkPassword (string: codeWord, string: message) {
  75.   int: passwordAttempts;
  76.   string: codeWordAttempt;
  77.   codeWord := strupper (codeWord);
  78.   for (passwordAttempts = 0; passwordAttempts < 3; passwordAttempts := passwordAttempts + 1) {
  79.     input_str (codeWordAttempt, INPUT_NLB_LINE | INPUT_ECHO | INPUT_NOCTRLC, '.', 20, message + COL_CYAN);
  80.     codeWordAttempt := strupper (codeWordAttempt);
  81.     if (codeWord = codeWordAttempt) return True;
  82.     print (str_bad_password_attempt + itostr (passwordAttempts+1)
  83.       + str_bad_password_attempt_sfx);
  84.     };
  85.   vidsync ();
  86.   return False;
  87.   }
  88.  
  89. // Dialout routines ----------------------------------------------------
  90.  
  91. // Dial calls the given phone number and returns the attempt's
  92. // status. Constants returned by dial:
  93.  
  94. #define CONNECT 0
  95. #define BUSY 1
  96. #define NOCARRIER 2
  97. #define NODIAL 3
  98. #define VOICE 4
  99. #define OTHER 5
  100. #define TIMEOUT 6
  101. #define USERABORT 7
  102. #define DIFFERENTBAUD 8
  103.  
  104. int dial (string: phoneNum, int: waitTime) {
  105.   int: counter, responseIdx, tempIdx;
  106.   long: oldBaudrate;
  107.   char: key;
  108.   string: message, tempStr;
  109.  
  110.   oldBaudrate := getBaudRate ();
  111.  
  112.   flushInput ();                                // Flush input buffer
  113.   println_direct (scr_dialing + phoneNum);
  114.   mdm_command (mdm_dial_pfx + phoneNum          // Perform dialout -
  115.     + mdm_dial_sfx);                            //   tell modem to dial
  116.   sleep (100);                                  // Wait 1 second
  117.   flushInput ();                                // Flush input buffer
  118.   for (counter:=0;counter < waitTime;           // Loop until timeout or modem returns message
  119.     counter := counter+ 1) {                    //
  120.     if (waitKey (100)) {                        // Wait 1 second
  121.       int: tmp;                                 //
  122.       message := "";                            // Initialize modem response string
  123.       do {                                      // Handle all the data returned by the modem
  124.         key := getch ();                        // Get one character
  125.         if (localkey ()) {                      // If the sysop hit a key,
  126.           log (str_sysop_abort_log);            //   record to log file
  127.           println_direct (scr_sysop_abort);     //   Display local message
  128.           return USERABORT;                     //   abort dialout
  129.           };                                    //
  130.         if (key >= 32) {                        // Don't add CR to the message string
  131.           tmp := strlen (message) + 1;          // These two ugly lines append a char
  132.           message := strpad (message, tmp,key); // to the message string
  133.           };                                    //
  134.         sleep (10);                             // Wait for another char to arrive
  135.         } while (kbhit ());                     // End loop if no more data waiting
  136.       println_direct (scr_modem_response + message);
  137.       log (str_modem_response_log + message);   // Record modem response to log file
  138.                                                 //
  139.                                                 // Now, determine what message was returned
  140.                                                 // by the modem and return appropriate result.
  141.  
  142.       responseIdx := strfind (message, msg_connect);
  143.       if (responseIdx) {
  144.         responseIdx := responseIdx + strlen (msg_connect);
  145.         while ((message [responseIdx] = ' ') and (responseIdx < strlen (message)))
  146.           responseIdx := responseIdx + 1;
  147.         for (tempIdx := 1;(message [responseIdx] >= '0')
  148.           and (message [responseIdx] <= '9');responseIdx := responseIdx + 1) {
  149.  
  150.           tempStr [tempIdx] := message [responseIdx];
  151.           tempIdx := tempIdx + 1;
  152.           };
  153.         if (oldBaudrate = strtol (tempStr)) return CONNECT;
  154.         return DIFFERENTBAUD;
  155.         };
  156.       if (strfind  (message,msg_no_carrier))    return NOCARRIER;
  157.       if (strfind  (message,msg_busy))          return BUSY;
  158.       if (strfind  (message,msg_no_dialtone))   return NODIAL;
  159.       if (strfind  (message,msg_voice))         return VOICE;
  160.       if (strfind  (message,msg_ringing) = False) {
  161.                                                 // Otherwise, unknown response.
  162.         log (str_unknown_message_log + message);// Record error
  163.         return OTHER;                           // Return error
  164.         };                                      //
  165.       };                                        //
  166.     }                                           //
  167.   mdm_command ("|");                            // Abort dialout
  168.   println_direct (scr_timeout);
  169.   log (str_connect_timeout_log);                // Record timeout to logfile
  170.   return TIMEOUT;                               // return timeout
  171.   }
  172.  
  173. // Redial dials the given number until either the number of attempts
  174. // is exceeded, VOICE or USERABORT is returned, or a successfull connect
  175. // occours. Redial returns True if a successful connect occoured, and
  176. // false otherwise. MaxAttempts is the maximum number of times the
  177. // dialout should be attempted, and delay is the delay between each
  178. // dialout attempt. WaitTime is the amount of time that max should
  179. // wait for the remote system to pick up.
  180.  
  181. int redial (string: phoneNum, int: maxAttempts, int: delay,
  182.   int: waitTime) {
  183.  
  184.   int: attempts, result, noDialRetry;
  185.  
  186.   log (str_dialing_user_log);
  187.  
  188.   for (attempts := 1;attempts <= maxAttempts; attempts := attempts + 1) {
  189.     println_direct (scr_verification_attempt + itostr (attempts));
  190.     log (str_dial_attempt_log + itostr (attempts));
  191.     result := dial (phoneNum, waitTime);
  192.     for (noDialRetry := 0; (noDialRetry < num_nodial_retries) and (result = NODIAL);
  193.       noDialRetry := noDialRetry + 1) {
  194.       sleep (num_nodial_retry_delay * 100);
  195.       log (str_nodial_retry_log);
  196.       result := dial (phoneNum, waitTime);
  197.       };
  198.     if (result = CONNECT) return True;
  199.     if (result = DIFFERENTBAUD) {
  200.       log (str_baudrate_changed_log);
  201.       if (num_baudrate_check_behaviour = 0) return True;
  202.       if ((num_baudrate_check_behaviour = 1) 
  203.         or ((attempts = maxAttempts) and (num_baudrate_check_behaviour = 3))) {
  204.         show_file (bad_baudrate_file);
  205.         mdm_command (mdm_hangup);
  206.         return False;
  207.         };
  208.       if (num_baudrate_check_behaviour = 2) {
  209.         hangupFlag := True;
  210.         return True;
  211.         };
  212.       if (num_baudrate_check_behaviour = 3) {
  213.         show_file (bad_baudrate_attempt_file);
  214.         };
  215.       };
  216.     if ((result = USERABORT) or (result = VOICE)) return False;
  217.     println_direct (scr_waiting_attempt);
  218.     sleep (100*delay);
  219.     };
  220.   return False;
  221.   }
  222.  
  223. // callBack is the routine that actually performs the call back
  224. // verification. It calls the given phone number and prompts the user
  225. // for the code word. If the code word matches codeWord,
  226. // then call back returns True.
  227.  
  228. int callBack (string: phoneNum, string: codeWord) {
  229.   int: connectStat;
  230.   string: codeWordAttempt, username;
  231.   int: passwordAttempts;
  232.   int: newPriv;
  233.  
  234.   username := usr.alias;
  235.   if (username = "") username := usr.name;
  236.  
  237. #ifndef ALLOW_LOCAL
  238.   if (id.local <> 1) {
  239. #endif
  240.     dcd_check (False);
  241.     print_direct (AVATAR_CLS);
  242.     println_direct (scr_verifying + usr.name);
  243.     println_direct (scr_any_key_to_abort);
  244.     mdm_command (mdm_hangup);
  245.     println_direct (scr_init_modem);
  246.     mdm_command (mdm_init);
  247.     connectStat := redial (phoneNum,num_attempts, num_delay,
  248.       num_connect_timeout);
  249.     if (connectStat = 0) log (str_fail_connect_log);
  250.     dcd_check (True);
  251.     if (connectStat = 0) return False;
  252. #ifndef ALLOW_LOCAL
  253.     };
  254. #endif
  255.  
  256.   show (welcome_back_file, str_welcome_back1 + username + str_welcome_back2); 
  257.  
  258.   if (num_ask_codeword) {
  259.     print (str_welcome_back3);
  260.     if (checkCodeWord (codeWord, str_code_request) = False) {
  261.       show (bad_code_file, str_bad_code);
  262.       log (str_bad_code_log);
  263.       return False;
  264.       };
  265.     }
  266.   else print ("\n");
  267.  
  268.   print ("\n");
  269.  
  270.   if ((usr.encrypted = False) and (num_ask_password)) {
  271.     if (checkPassword (usr.pwd, str_pwd_request) = False) {
  272.       show (bad_password_file, str_bad_password);
  273.       log (str_bad_password_log);
  274.       return False;
  275.       };
  276.     };
  277.  
  278.   return True;
  279.   }
  280.  
  281. #ifdef flg_use_codeword
  282. string nonsenseWord () {
  283.   int: idx;
  284.   char: c;
  285.   string: s;
  286.  
  287.   for (idx := 1; idx <= num_codeword_length; idx := idx + 1) {
  288.     c := rand ();
  289.     for (;c > 25; c := c - 26);
  290.     s [idx] := 'A' + c;
  291.     };
  292.   return s;
  293.   }
  294. #endif
  295.  
  296. #ifndef flg_use_codeword
  297. string nonsenseWord () {
  298.   int: idx;
  299.   char: c;
  300.   string: s;
  301.  
  302.   for (idx := 1; idx <= num_codeword_length; idx := idx + 1) {
  303.     c := rand ();
  304.     for (;c > 9; c := c - 10);
  305.     s [idx] := '0' + c;
  306.     };
  307.   return s;
  308.   }
  309. #endif
  310.  
  311.  
  312. void verify (string: dialStr, string: newPhone, string: city, int: dialType) {
  313.   string: codeWord;
  314.   int: success;
  315.  
  316.   seed := time ();
  317.   codeWord := nonsenseWord ();
  318.  
  319.   show_file (help_file);
  320.  
  321.   if (input_list_ani ("Yn\r", str_press_yn, str_proceed) = 'N') {
  322.     show_file (abort_file);
  323.     return;
  324.     };
  325.   if (num_ask_codeword) {
  326.     print (AVATAR_CLS);
  327.     print (str_tell_codeword + codeWord + "\n");
  328.     print (str_tell_codeword2);
  329.     print (COL_WHITE);
  330.     flushInput ();
  331.     menu_cmd (MNU_PRESS_ENTER, "");
  332.     };
  333.   print (str_hanging_up);
  334.  
  335.   success := callBack (dialStr, codeWord);
  336.  
  337.   if (success) {
  338.     int: newPriv;
  339.     usr.dataphone := newPhone;
  340.     if (num_update_city and (city <> ""))
  341.       usr.city := city;
  342.     log (str_user_verified_log);
  343.     newPriv := class_to_priv (str_new_sec);
  344.     if (usr.priv < newPriv)
  345.       usr.priv := newPriv;
  346.     usr.xkeys := usr.xkeys + str_new_keys;
  347.     stripStr (usr.xkeys,str_old_keys);
  348.     timeadjustsoft (num_time_bonus * 60);
  349.     padlock_log (newPhone + str_success_sfx_log);
  350.     show (success_file, str_success_message);
  351.     }
  352.   else {
  353.     log (str_fail_log);
  354.     padlock_log (newPhone + str_fail_sfx_log);
  355.     show (fail_file, str_fail_message);
  356.     };
  357.   if (dialType = DNLD) {
  358.     show_file (hangup_ld_file);
  359.     log (str_hangup_ld_log);
  360.     sleep (800);
  361.     mdm_command (mdm_hangup);
  362.     };
  363.   if (hangupFlag or num_always_hangup) {
  364.     show_file (success_hangup_file);
  365.     log (str_success_hangup_log);
  366.     sleep (1000);
  367.     mdm_command (mdm_hangup);
  368.     };
  369.   }
  370.  
  371. #endif
  372.  
  373.